#ifndef __PROXY_EVENT_H__
#define __PROXY_EVENT_H__
#include "stdafx.h"
#include "nfapi.h"
#include "tcpproxy.h"
#include "UserMgr.h"
using namespace nfapi;

/**
*	Filtering events
**/
class ProxyEventHandler : public NF_EventHandler
{
private:
	TcpProxy::TCPProxy *m_TCPProxy;
	UserMgr *m_UserMgr;
public:
	void senEventhandle(TcpProxy::TCPProxy*, UserMgr*);
    /**
	* Called immediately after starting the filtering thread.
	* Use this event for thread-specific initialization, e.g. calling
	* CoInitialize() etc.
	**/
    virtual void threadStart() {}

    /**
	* Called before stopping the thread.
	**/
    virtual void threadEnd() {}

    //
    // TCP events
    //

    /**
	* Called before establishing an outgoing TCP connection,
	* when NF_INDICATE_CONNECT_REQUESTS flag is specified in an appropriate rule.
	* It is possible to change pConnInfo->filteringFlag and pConnInfo->remoteAddress
	* in this handler. The changes will be applied to connection.
	* @param id Unique connection identifier
	* @param pConnInfo Connection parameters, see <tt>NF_TCP_CONN_INFO</tt>
	**/
    virtual void tcpConnectRequest(ENDPOINT_ID id, PNF_TCP_CONN_INFO pConnInfo);

    /**
	* Called after successful establishing the incoming or outgoing TCP connection.
	* @param id Unique connection identifier
	* @param pConnInfo Connection parameters, see <tt>NF_TCP_CONN_INFO</tt>
	**/
    virtual void tcpConnected(ENDPOINT_ID id, PNF_TCP_CONN_INFO pConnInfo) {}

    /**
	* Called after closing the connection identified by id.
	* @param id Unique connection identifier
	* @param pConnInfo Connection parameters, see <tt>NF_TCP_CONN_INFO</tt>
	**/
    virtual void tcpClosed(ENDPOINT_ID id, PNF_TCP_CONN_INFO pConnInfo) {}

    /**
	* Indicates the buffer received from server.
	* @param id Unique connection identifier
	* @param buf Pointer to data buffer
	* @param len Buffer length
	**/
    virtual void tcpReceive(ENDPOINT_ID id, const char *buf, int len) {}

    /**
	* Indicates the buffer sent from the local socket.
	* @param id Unique connection identifier
	* @param buf Pointer to data buffer
	* @param len Buffer length
	**/
    virtual void tcpSend(ENDPOINT_ID id, const char *buf, int len) {}

    /**
	* Informs that the internal buffer for receives is empty and
	* it is possible to call nf_tcpPostReceive for pushing receives
	* via specified connection.
	* @param id Unique connection identifier
	**/
    virtual void tcpCanReceive(ENDPOINT_ID id) {}

    /**
	* Informs that the internal buffer for sends is empty and
	* it is possible to call nf_tcpPostSend for pushing sends
	* via specified connection.
	* @param id Unique connection identifier
	**/
    virtual void tcpCanSend(ENDPOINT_ID id) {}

    //
    // UDP events
    //

    /**
	* Called after creating UDP socket.
	* @param id Unique socket identifier
	* @param pConnInfo Socket parameters, see <tt>NF_UDP_CONN_INFO</tt>
	**/
    virtual void udpCreated(ENDPOINT_ID id, PNF_UDP_CONN_INFO pConnInfo) {}

    /**
	* Called before establishing an outgoing UDP connection,
	* when NF_INDICATE_CONNECT_REQUESTS flag is specified in an appropriate rule.
	* It is possible to change pConnReq->filteringFlag and pConnReq->remoteAddress
	* in this handler. The changes will be applied to connection.
	* @param id Unique connection identifier
	* @param pConnInfo Connection parameters, see <tt>NF_UDP_CONN_REQUEST</tt>
	**/
    virtual void udpConnectRequest(ENDPOINT_ID id, PNF_UDP_CONN_REQUEST pConnReq) {}

    /**
	* Called after closing UDP socket identified by id.
	* @param id Unique socket identifier
	* @param pConnInfo Socket parameters, see <tt>NF_UDP_CONN_INFO</tt>
	**/
    virtual void udpClosed(ENDPOINT_ID id, PNF_UDP_CONN_INFO pConnInfo) {}

    /**
	* Indicates the buffer received from server.
	* @param id Unique socket identifier
	* @param options UDP options
	* @param remoteAddress Source address
	* @param buf Pointer to data buffer
	* @param len Buffer length
	**/
    virtual void udpReceive(ENDPOINT_ID id, const unsigned char *remoteAddress, const char *buf, int len, PNF_UDP_OPTIONS options) {}

    /**
	* Indicates the buffer sent from the local socket.
	* @param id Unique socket identifier
	* @param options UDP options
	* @param remoteAddress Destination address
	* @param buf Pointer to data buffer
	* @param len Buffer length
	**/
    virtual void udpSend(ENDPOINT_ID id, const unsigned char *remoteAddress, const char *buf, int len, PNF_UDP_OPTIONS options) {}

    /**
	* Informs that the internal buffer for receives is empty and
	* it is possible to call nf_udpPostReceive for pushing receives
	* via specified socket.
	* @param id Unique socket identifier
	**/
    virtual void udpCanReceive(ENDPOINT_ID id) {}

    /**
	* Informs that the internal buffer for sends is empty and
	* it is possible to call nf_udpPostSend for pushing sends
	* via specified socket.
	* @param id Unique socket identifier
	**/
    virtual void udpCanSend(ENDPOINT_ID id) {}
};

#endif // ! __PROXY_EVENT_H__
